package string;

import org.junit.Test;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/3/19:21:54
 * <P> Description:
 */

public class StringTest {
    @Test
    public void addString(){
        String a1 = "abd";
        String a2 = "abd";
        //true 共用同一个字符常量池的字符串常量 比较地址
        System.out.println(a1==a2);
        System.out.println(a1);
        System.out.println(a2);
    }

    @Test
    public void addString1(){
        String a1 = "abd";
        String a2 = "abd";
        a2="hello";
        //false 字符串常量池会新增hello
        System.out.println(a1==a2); //
        System.out.println(a1);
        System.out.println(a2);
    }

    @Test
    public void addString2(){
        String a1 = "abd";
        String a2 = "abd";
        a2 +="hello";
        //false 字符串常量池会新增abdhello
        System.out.println(a1==a2); //
        System.out.println(a1);
        System.out.println(a2);
    }

    @Test
    public void addString3(){
        String a1 = "abd";
        //mbd
        String a2 = a1.replace('a','m');

        // false a2返回新的String
        System.out.println(a1==a2); //
        System.out.println(a1);
        System.out.println(a2);
    }

    @Test
    public void addString4(){
        //-XX:StringTableSize=60013 1.8默认长度
        String a1 = "abd";
        try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    /**
     * <P>Author ideaAdmin
     * <P>TODO: 传入str 和 char数组 在里面更改它们的值
     * <P>Date 22:50 2022/3/19
     * <P>* @param str
    * @param ch
     * <P>* @return void
     **/
    public void  change(String str,char[] ch){
        str = "test.ok";
        ch[0] = 'c';
    }

    String str = "good";
    char[] ch = {'t','e','s','t'};

    @Test
    public void isChange(){
        change(str,ch);
        //good
        System.out.println(str);
        //cest
        System.out.println(ch);
    }

}
